<{include file="Public/top.html" }>
<style>
    .pricehead{
        font-weight: 600;
    }
    .pricehead .ui-text{
        text-align: center;
        border:none;}
</style>
</head>
	<body>
		<div id="warpper">
            <div class="content">
                <div class="location">家政服务</div>
                <{include file="./nav.html" }>
                <div class="topic">新增项目</div>
                <form action="<{U('Events/edit')}>" method="post" class="ui-form">
                <div class="form-box border0 border-box">
                    <div class="ui-form-item ">
                        <label class="ui-label">排序</label>
                        <input type="text" class="ui-text" name="showOrder" value="<{$data['showOrder']|default:0}>"  required/>
                    </div>
                    <div class="ui-form-item ">
                        <label class="ui-label">标题</label>
                        <input type="text" class="ui-text" name="title" value="<{$data['title']}>" required/>
                    </div>

                    <div class="ui-form-item2 inline-block uploader">
                        <label class="ui-label ">列表图片</label>
                            <span class="picture_box picture_270" id="listPic">
                                <input type="hidden" value="<{$data['imgList']}>" id="imgList" name="imgList" class="ui-button"/>
                                <div class="a-imgBox" id="imgBox" <{if $data['imgList']}>style="display:block"<{else}>style="display:none;"<{/if}> >
                                    <a href="javascript:;" class="a-close" onclick="deleteListPic()"></a>
                                    <img src="<{$data['imgList']}>" width="240" height="180" />
                                </div>
                                <div >
                                    <a href="javascript:;" class="a-upload">
                                        <input type="file" name="file" >
                                    </a>
                                    <i class="uptxt">上传图片</i>
                                    <i>240*180</i>
                                </div>
                            </span>

                    </div>
                    <div class="ui-form-item" style="vertical-align:top;">
                        <label class="ui-label">列表简介</label>
                        <textarea class="ui-textarea " name="brief"  rows="20" ><{$data['brief']}></textarea>
                    </div>


            <div class="ui-form-item2 uploader" style="min-height: 157px">
                <label class="ui-label">详情轮播图片:</label>
                <div style="width: 775px;display: inline-block;">
                    <{foreach from=explode(',',$data['album']) item=img}>
                        <{if $img }>
                            <span class="picture_box picture_150">
                                <div class="a-imgBox"   style="display:block;">
                                    <a href="javascript:void(0);" class="a-close" onclick="removeElement(this)"></a>
                                    <img src="<{$preUploadUrl}><{$img}>" width="150" height="150" />
                                    <input type="hidden" name="album[]" value="<{$img}>" />
                                </div>
                            </span>
                        <{/if}>
                    <{/foreach}>

                    <span class="picture_box picture_150 " id="addImg" style="position: absolute;">
                        <div>
                            <a href="javascript:;" class="a-upload">
                                <input type="file" name="file"  >
                            </a>
                            <i>上传图片</i>
                            <i>750*330</i>
                        </div>
                    </span>
                </div>

            </div>



                    <div class="ui-form-item">
                        <label class="ui-label">上线时间</label>
                        <input id="beginShowTime" name="beginShowTime" readonly required class="ui-select" value='<{$data["beginShowTime"]|date_format:"%Y-%m-%d %H:%M"}>' type="text" />
                    </div>

                    <div class="reply_box">
                        <label class="ui-label">详情内容</label>
                        <textarea id="editor" name="detail" required class="edui-default inline-block" ><{$data['detail']}></textarea>
                    </div>


                    <div class="reply_box">
                        <label class="ui-label">分享内容</label>
                        <div class="reply_con inline-block">
                            <input type="text" name="share_desc" value="<{$data['share_desc']}>" class="ui-text"  required/>
                        </div>
                    </div>

                    <div class="reply_box">
                        <label class="ui-label">显示标签</label>
                        <input type="text" name="tag" value="<{$data['tag']}>" class="ui-text"  required/>
                        <i>逗号分隔，随机提取两项显示</i>
                    </div>

                    <div class="ui-form-item">
                        <label class="ui-label ">价格配置</label>
                        <div class="inline-block">
                            <div class="pricehead">
                            <span class="ui-text" style="width: 6rem">项目名称</span>
                            <span class="ui-text" style="width: 5rem">单价</span>
                            <span class="ui-text" style="width: 12rem">计价单位</span>
                            <span class="ui-text" style="width: 5rem">可用积分</span>
                            <span class="ui-text" style="width: 5rem">可抵金额</span>
                            </div>
                            <{foreach from=$priceSet item=item}>
                            <div class="oneset">
                                <input type="text" class="ui-text inline-block"  value="<{$item[0]}>" style="width: 6rem" name="name[]" placeholder="项目名称" required/>
                                <input type="number" class="ui-text inline-block"  value="<{$item[1]}>" style="width:5rem;text-align: center;" name="fee[]" placeholder="单价：元" required/>
                                <input type="text" class="ui-text inline-block"  value="<{$item[2]}>" style="width: 12rem"name="unit[]" placeholder="计价单位，如台/平米/小时" required/>
                                <input type="number" class="ui-text inline-block"  value="<{$item[3]}>" style="width:5rem;text-align: center;" name="point[]" placeholder="积分" />
                                <input type="number" class="ui-text inline-block"  value="<{$item[4]}>" style="width:5rem;text-align: center;" name="reduce[]" placeholder="抵扣金额" />
                                <input type="button" value="--" onclick="delPrice(this)" />
                            </div>
                            <{/foreach}>
                            <div id="moreSet">+更多价格设置</div>
                        </div>
                    </div>

                <div class="integral_btn-group">
                    <input type="submit" value="提交" class="ui-button"/>
                    <input type="hidden" name="id" value="<{$id}>" class="ui-button"/>
                </div>

                </form>
            </div>
		</div>
        <{include file="Public/foot.html" }>

        <{include file="Public/ueditor.html" }>
		<script>
            var eventsAdd = "<{U('add')}>";
            var eventsEdit = "<{U('edit')}>";
            var listUrl="<{U('index')}>";

            datePickter('beginShowTime');


            $(document).ready(function(){
                $('#moreSet').click(function(){
                    $(this).before('<div class="oneset"> <input type="text" class="ui-text inline-block"   style="width: 6rem" name="name[]" placeholder="项目名称" required/>    <input type="number" class="ui-text inline-block"   style="width:5rem;text-align: center;" name="fee[]" placeholder="单价：元" required/>       <input type="text" class="ui-text inline-block"   style="width: 12rem"name="unit[]" placeholder="计价单位，如台/平米/小时" required/>     <input type="number" class="ui-text inline-block"  value="<{$item[3]}>" style="width:5rem;text-align: center;" name="point[]" placeholder="积分" /> <input type="number" class="ui-text inline-block"  value="<{$item[4]}>" style="width:5rem;text-align: center;" name="reduce[]" placeholder="抵扣金额" />  <input type="button" value="--" onclick="delPrice(this)" />                            </div>' )             })

                $("form").submit(function () {
                    if( !$("#imgList").val() ){
                        layer.msg('请上传列表图片！');
                        return false;
                    }
                    if($('.oneset').size()==0){
                        layer.msg('价格设置是必须的唷！');
                        return false;
                    }


                    if( !UE.getEditor('editor').getContent() ){
                        layer.msg('请填写详情！');
                        return false;
                    }
                    //return true;
                    $.post(eventsEdit,$(this).serialize(), function(data){
                        if(data.status!=0){
                            if(data.mark){
                                layer.msg(data.mark);
                            }else{
                                layer.msg(data.msg);
                            }
                        }else{
                            layer.msg(data.msg);
                            setTimeout(2000,function(){location.href = listUrl;});

                        }
                    }, 'json');
                    return false;
                });



            });


            function delPrice(obj){
                $(obj).parent().remove();
            }



            (function ($) {
                'use strict';
                $.fn.uploader2 = function () {
                    return this.each(function () {
                        var $this = $(this);
                        var $img = $this.find('img');
                        var $file = $this.find('input[type=file]');
                        var $hidden = $this.find('input[type=hidden]');
                        var $txt = $this.find('i.uptxt');
                        $file.AjaxFileUpload({
                            action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_HOUSEWORK_MARQUEE',
                            onSubmit: function () {
                                $txt.text('上传中');
                            },
                            onComplete: function (filename, response) {
                                if(parseInt(response.id)>0){
                                    $txt.text("上传成功");
                                    newImg(response.msg);
                                }else{
                                    $txt.text(response.msg);
                                }
                            }
                        });
                    });
                }
            })(jQuery);
            $('#addImg').uploader2();


            (function ($) {
                'use strict';
                $.fn.uploader = function () {
                    return this.each(function () {
                        var $this = $(this);
                        var $img = $this.find('img');
                        var $file = $this.find('input[type=file]');
                        var $hidden = $this.find('input[type=hidden]');
                        var $txt = $this.find('i.uptxt');
                        var $imgBox = $this.find('div[id=imgBox]');
                        $file.AjaxFileUpload({
                            action: './api.php?m=Api&c=index&a=ajaxUpload&from=IMG_HOUSEWORK_ITEM',
                            onSubmit: function () {
                                $txt.text('上传中');
                            },
                            onComplete: function (filename, response) {
                                if(parseInt(response.id)>0){
                                    $txt.text("上传成功");
                                    $hidden.attr('value', response.msg);
                                    $img.attr("src",response.msg);
                                    $imgBox.css('display','block');
                                }else{
                                    $txt.text(response.msg);
                                }

                            }
                        });
                    });
                }
            })(jQuery);

            $('#listPic').uploader();

            //删除图片
            function deleteListPic() {
                $('#imgBox').hide();
                $('.uptxt').text('上传图片');
                $('#imgList').val('');
            }

            function removeElement(obj){
                $(obj).parents('.picture_150').remove();
            }

            function newImg(src){
                $img=$('<span class="picture_box picture_150"><div class="a-imgBox"  style="display:block;"><a href="javascript:void(0);" class="a-close" onclick="removeElement(this)"></a><img src="<{$preUploadUrl}><{$img}>" width="150" height="130" /> <input type="hidden" name="album[]" value="" /></div></span>');
                $('#addImg').before($img);
                $img.find('input[type=hidden]').val(src);
                $img.find('img').attr('src',src);
            }
		</script>
	</body>
</html>
